package com.wang.utils;

import java.util.List;

/**
 * @Classname PageUtil
 * @Description TODO
 * @Date 2024/11/11 9:17
 * @Created by pc
 */
public class PageUtil<T> {
    private Integer pageSize = 2;
    private Integer totalPage;
    private Integer currentPage;
    private Integer totalSize;
    private List<T> data;

    public PageUtil() {
    }

    public PageUtil(Integer pageSize, Integer totalPage, Integer currentPage, Integer totalSize, List<T> data) {
        this.pageSize = pageSize;
        this.totalPage = totalPage;
        this.currentPage = currentPage;
        this.totalSize = totalSize;
        this.data = data;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }

    public Integer getTotalSize() {
        return totalSize;
    }

    public void setTotalSize(Integer totalSize) {
        this.totalSize = totalSize;
        setTotalPageByTotalSize();
    }

    private void setTotalPageByTotalSize() {
        if(this.totalSize == 0){
            this.totalPage = 0;
        }else if(this.totalSize % this.pageSize == 0){
            this.totalPage = this.totalSize / this.pageSize;
        }else{
            this.totalPage = this.totalSize / this.pageSize + 1;
        }
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "PageUtil{" +
                "pageSize=" + pageSize +
                ", totalPage=" + totalPage +
                ", currentPage=" + currentPage +
                ", totalSize=" + totalSize +
                ", data=" + data +
                '}';
    }
}
